$(document).ready(function(){
	$('.cariButton').click(function(e){
		$("html, body").animate({ scrollTop: 0 }, 500);
		$('#inputCari').focus();
		e.preventDefault();
	})
});

function topcontent(json) {
	document.write('<ul class="list-unstyled top-content clearfix">');
	for (var i = 0; i < json.feed.entry.length; i++)
	{
		for (var j = 0; j < json.feed.entry[i].link.length; j++) {
			if (json.feed.entry[i].link[j].rel == 'alternate') {
				break;
			}
		}

		if (json.feed.entry[i].media$thumbnail) {
			if (i == 0){
				var entryImg = json.feed.entry[i].media$thumbnail.url.replace("/s72-c/","/s320-c/");
			}else{
				var entryImg = '';
			}
		}else{
			var entryImg = 'http://placehold.it/300x300&text=no%20preview';
		}
		var entryCategory = json.feed.entry[i].category[0].term;
		var entryUrl = json.feed.entry[i].link[j].href;
		var entryTitle = json.feed.entry[i].title.$t;
		var item = '<li> \
						<div class="category '+entryCategory+'">'+entryCategory+'</div> \
						<div class="img" style="background:url('+entryImg+') no-repeat"></div> \
						<div class="title"><a title="'+entryTitle+'" href="'+entryUrl+'">'+entryTitle+'</a></div> \
					</li> \
					';
		document.write(item);
	}
	document.write('<h4>TOP NEWS</h4>');
	document.write('</ul>');
}


function maincontent(json) {
	if(typeof(json.feed.entry) != 'undefined'){
		document.write('<div class="col-xs-12"><ul class="list-unstyled">');
		for (var i = 0; i < json.feed.entry.length; i++)
		{
			for (var j = 0; j < json.feed.entry[i].link.length; j++) {
				if (json.feed.entry[i].link[j].rel == 'alternate') {
					break;
				}
			}

			if (json.feed.entry[i].media$thumbnail) {
				if (i == 0){
					var entryImg = json.feed.entry[i].media$thumbnail.url.replace("/s72-c/","/s300-c/");
				}else{
					var entryImg = '';
				}
			}else{
				var entryImg = 'http://placehold.it/300x300&text=no%20preview';
			}
			var entryCategory = json.feed.entry[i].category[0].term;
			var entryUrl = json.feed.entry[i].link[j].href;
			var entryTitle = json.feed.entry[i].title.$t;
			var item = '<li> \
							<div class="category '+entryCategory+'">'+entryCategory+'</div> \
							<div class="img-thumbnail"><div class="img" style="background:url('+entryImg+') no-repeat"></div></div> \
							<div class="title"><a title="'+entryTitle+'" href="'+entryUrl+'">'+entryTitle+'</a></div> \
						</li> \
						';
			document.write(item);
		}
		document.write('</ul></div>');
	}
}


function unik(json) {
	document.write('<ul class="list-unstyled">');
	for (var i = 0; i < json.feed.entry.length; i++)
	{
		for (var j = 0; j < json.feed.entry[i].link.length; j++) {
			if (json.feed.entry[i].link[j].rel == 'alternate') {
				break;
			}
		}

		if (json.feed.entry[i].media$thumbnail) {
			var entryImg = json.feed.entry[i].media$thumbnail.url.replace("/s72-c/","/s70-c/");
		}else{
			var entryImg = 'http://placehold.it/70x70&text=no%20preview';
		}
		var entryCategory = json.feed.entry[i].category[0].term;
		var entryUrl = json.feed.entry[i].link[j].href;
		var entryTitle = json.feed.entry[i].title.$t;
		var item = '<li> \
						<a class="clearfix" title="'+entryTitle+'" href="'+entryUrl+'"> \
						<div class="img pull-left"><img src="'+entryImg+'"/></div> \
						<div class="title pull-left">'+entryTitle+'</div> \
						</a> \
					</li> \
					';
		document.write(item);
	}
	document.write('</ul>');
}

function otomotif (json){
	if(typeof(json.feed.entry) != 'undefined'){
		document.write('<ul class="list-unstyled">');
		for (var i = 0; i < json.feed.entry.length; i++)
		{
			for (var j = 0; j < json.feed.entry[i].link.length; j++) {
				if (json.feed.entry[i].link[j].rel == 'alternate') {
					break;
				}
			}

			if (json.feed.entry[i].media$thumbnail) {
				if (i == 0){
					var entryImg = json.feed.entry[i].media$thumbnail.url.replace("/s72-c/","/s300-c/");
				}else{
					var entryImg = json.feed.entry[i].media$thumbnail.url.replace("/s72-c/","/s70-c/");
				}
			}else{
				var entryImg = 'http://placehold.it/70x70&text=no%20preview';
			}
			var entryUrl = json.feed.entry[i].link[j].href;
			var entryTitle = json.feed.entry[i].title.$t;
			var item = '<li> \
							<a class="clearfix" title="'+entryTitle+'" href="'+entryUrl+'"> \
							<div class="img pull-left" style="background:url('+entryImg+') no-repeat"></div> \
							<div class="title pull-left">'+entryTitle+'</div> \
							</a> \
						</li> \
						';
			document.write(item);
		}
		document.write('</ul>');
	}
}